<%@page import="wap.rockvilletech.util.imaging.Inputvalidation"%>
<%@include file="includes/jspf/header.jspf" %>
<%
	Inputvalidation obj_Validation = new Inputvalidation();
	
	String strSenderName = "";
	String strReceiverName = "";
	String strReceiverMSISDN = "";
	String strContentId = "";
	String strSourceFile = "";
	String SoF = "";
	
	String error_Msg = "";
	boolean hasError = false;
	
	try {
	    strSenderName = request.getParameter("sendername");
	    strReceiverName = request.getParameter("receivername");
	    strReceiverMSISDN = request.getParameter("receivernumbers");
	    strWidth = request.getParameter("w");
	    strHeight = request.getParameter("h");
	    strSourceFile = request.getParameter("img");
	    SoF = request.getParameter("sof");
	    strContentId = request.getParameter("cid");
	
	} catch (Exception e) {
	    log.error("", e);
	}

	// VALIDATE the required fields 
	// if any required field is missing, send the user back
	if(strReceiverMSISDN == null || strReceiverMSISDN.isEmpty()) {
	    hasError = true;
	    error_Msg += "<div>Required Recipient's Number is missing</div>";
	} else {
            strReceiverMSISDN = obj_Validation.validateMSISDN(strReceiverMSISDN.trim());
	    if(strReceiverMSISDN.equalsIgnoreCase("INVALID")) {
	        hasError = true;
	        error_Msg += "<div>Please enter a valid Recipient's Number</div>";
	    }
	}
	if(strSenderName == null || strSenderName.isEmpty()) {
	    hasError = true;
	    error_Msg += "<div>Required Sender name is missing</div>";
	}
	if(strReceiverName == null || strReceiverName.isEmpty()) {
	    hasError = true;
	    error_Msg += "<div>Required Recipient's name is missing</div>";
	}
	if(strContentId == null || strContentId.isEmpty()) {
	    hasError = true;
	    error_Msg += "<div>Error processing your request, please try later!</div>";
	}
	
	if(hasError) {
	    log.debug("Error caught in cardPreview.jsp\nError: "+error_Msg);
	    out.print("<div align='center' style='color: red;'>" + error_Msg + "</div>");
	}
	else {
		int cardInfoId = ugb.saveCardSenderInfo(strSenderName, strReceiverName, strReceiverMSISDN, strContentId);
		%>

		<div align="center">
                <%
                if(cardInfoId!=-1){
                %>
        	<p class="txt" align="center">Your card has been Customized</p>        
                <div style="padding-bottom: 20px;">
                <img alt="Greeting Card Preview" id="imgEditFile" src="<%=context_Path%>/renderImage?sendername=<%=strSenderName%>&sendermessage=<%=strReceiverName%>&s=0&repo=CBP&cid=<%=cardInfoId%>&h=<%=strHeight%>&img=<%=strSourceFile%>&w=<%=strWidth%>"/>
                </div>
			<div align="center" style="padding-bottom: 5px;"><a class="service_link" href="sms:6213?body=card <%=cardInfoId%>">Click Here</a> to send your card to <%=strReceiverName%> (@Rs.10+tax)
			<br/>
			If the above link doesn't work, SMS "<b>card <%=cardInfoId%></b>" (to -->) <b>6213</b></div>
                <%
                }else{
                    out.println("<p class=\"txt\" align=\"center\">Please Try Again."+request.getHeaders("referer")+"</p>");
                }
                %>
		</div>					
		<%--
        <form action="<%=context_Path%>/sendcard" method="get" name="formPreview">
            <input type="hidden" name="senderName" value="<%=strSenderName%>" />
            <input type="hidden" name="receiverName" value="<%=strReceiverName%>" />
            <input type="hidden" name="recvGSM" value="<%=strReceiverMSISDN%>" />
            <input type="hidden" name="w" value="<%=strWidth%>"/>
            <input type="hidden" name="h" value="<%=strHeight%>"/>
            <input type="hidden" name="contentID" value="<%=%>" />
            <input type="hidden" name="sof" value="<%=SoF%>"/>            
            <table align="center">
                <tr><td>
                        <p class="txt" align="center">Your card has been Customized</p>
                        <div align="center">
                            <div style="padding-bottom: 20px;">
                                <img alt="Greeting Card Preview" id="imgEditFile" src="<%=context_Path%>/renderImage?sendername=<%=strSenderName%>&sendermessage=<%=strReceiverName%>&s=0&repo=CBP&cid=<%=request.getParameter("cid").toString()%>&h=<%=strHeight%>&img=<%=strSourceFile%>&w=<%=strWidth%>"/>
                            </div>
                            <input type="submit" value="Send Card">
                        </div>
                </td></tr>
            </table>
        </form>
         --%>
        <%
	}
	%>
<%@include file="includes/jspf/footer.jspf" %>
<% ugb.LogVisit("", "cardPreview", "", "", "", "","Ugreeting", request.getQueryString()); %>